package com.lagou.edu.controller;

import com.edu.lagou.service.UserService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @program: stage-3-module-5
 * @description:
 * @author: zhangxiaoyang
 * @date: 2020-09-14 23:09
 **/
@RestController
@RequestMapping("/user")
public class UserController {

    @Reference
    private UserService userService;


    @PostMapping("/register/{email}/{code}/{password}")
    public Boolean register(@PathVariable("email") String email, @PathVariable("code") String code, @PathVariable("password") String password, HttpServletResponse response) {
        return userService.register(email, code, password, response);
    }

    @GetMapping("/isRegistered/{email}")
    public Boolean checkRegister(@PathVariable("email") String email) {
        return userService.checkRegister(email);
    }

    @GetMapping("/login/{email}/{password}")
    public String login(@PathVariable("email") String email, @PathVariable("password") String password, HttpServletResponse response) {
        return userService.login(email, password, response);
    }

    @GetMapping("/info/{token}")
    public String createToken(@PathVariable("token") String token) {
        return userService.getByToken(token);
    }

}
